<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <!-- 样 式 文 件 -->
    <link rel="stylesheet" href="__STATIC__/component/pear/css/pear.css" />
    <link rel="stylesheet" href="__STATIC__/admin/css/other/login.css" />
</head>
<!-- 代 码 结 构 -->
<body background="__STATIC__/admin/images/background2.svg" style="background-size: cover;">
<form class="layui-form" action="javascript:void(0);" style="margin-top: 100px !important;">
    <div class="layui-form-item">
        <img class="logo" src="__STATIC__/admin/images/logo.png" />
        <div class="title">Da Update</div>
        <div class="desc">
            软 件 更 新 版 本 推 送 管 理 系 统
        </div>
    </div>
    <div class="layui-form-item">
        <input placeholder="账 户 : " name="username" class="layui-input"  />
    </div>
    <div class="layui-form-item">
        <input placeholder="密 码 : " type="password" name="password" class="layui-input"  />
    </div>
    <div class="layui-form-item">
        <input placeholder="验证码 : " name="captcha" class="code layui-input layui-input-inline"  />
        <img src="{:captcha_src()}" id="captcha" width="110" title="点击刷新验证码" onclick="refreshCaptcha()" class="codeImage" />
    </div>
    <div class="layui-form-item">
        <input type="checkbox" name="remember" title="7 天免登陆" lay-skin="primary">
    </div>
    <div class="layui-form-item">
        <button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
            登 入
        </button>
    </div>
</form>
<!-- 资 源 引 入 -->
<script src="__STATIC__/component/layui/layui.js"></script>
<script src="__STATIC__/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'button', 'popup', 'jquery'], function() {
        let form = layui.form;
        let button = layui.button;
        let popup = layui.popup;
        let $ = layui.jquery;

        // 登 录 提 交
        form.on('submit(login)', function(data) {
            let loginBtn = button.load({
                elem: '.login'
            });
            $.ajax({
                type: "POST",
                data: data.field,
                success: function (res) {
                    loginBtn.stop();
                    if (res.code == 0){
                        popup.success("登录成功", function() {
                            location.href = res.url;
                        });
                    } else {
                        popup.failure(res.msg, function() {
                            refreshCaptcha();
                        });
                    }
                }, error: function () {
                    loginBtn.stop();
                    popup.failure("登录失败", function() {
                        refreshCaptcha();
                    });
                }
            });
            return false;
        });

        // 刷新验证码
        window.refreshCaptcha = function() {
            $('#captcha').attr('src', '{:captcha_src()}?'+Math.random());
        }

        // 回车监听
        $(document).on('keydown', 'input[name=captcha]', function (event) {
            if (event.keyCode == 13) {
                $('.login').click();
            }
        });
    });
</script>
</body>
</html>
